namespace XRM.Security.DataAccess.Context
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class UserInfoSystemGrant : DbMigration
    {
        public override void Up()
        {
            Sql("delete from UserInfoSystem");

            AddColumn("dbo.UserInfoSystem", "GrantDate", c => c.DateTime(nullable: false));
            AddColumn("dbo.UserInfoSystem", "GrantSystemUserId", c => c.Int(nullable: false));
            AddColumn("dbo.UserInfoSystem", "RevokeDate", c => c.DateTime());
            AddColumn("dbo.UserInfoSystem", "RevokeSystemUserId", c => c.Int());
            CreateIndex("dbo.UserInfoSystem", "GrantSystemUserId");
            CreateIndex("dbo.UserInfoSystem", "RevokeSystemUserId");
            AddForeignKey("dbo.UserInfoSystem", "GrantSystemUserId", "dbo.SystemUser", "Id", cascadeDelete: true);
            AddForeignKey("dbo.UserInfoSystem", "RevokeSystemUserId", "dbo.SystemUser", "Id");
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.UserInfoSystem", "RevokeSystemUserId", "dbo.SystemUser");
            DropForeignKey("dbo.UserInfoSystem", "GrantSystemUserId", "dbo.SystemUser");
            DropIndex("dbo.UserInfoSystem", new[] { "RevokeSystemUserId" });
            DropIndex("dbo.UserInfoSystem", new[] { "GrantSystemUserId" });
            DropColumn("dbo.UserInfoSystem", "RevokeSystemUserId");
            DropColumn("dbo.UserInfoSystem", "RevokeDate");
            DropColumn("dbo.UserInfoSystem", "GrantSystemUserId");
            DropColumn("dbo.UserInfoSystem", "GrantDate");
        }
    }
}
